package com.poc.party.service.wiredrule;

import com.meta.common.ConstDef;
import com.meta.counter.service.CounterService;
import com.meta.nd.service.WiredService;
import com.meta.nd.util.SpringBeanUtil;
import com.meta.nd.vo.Nv;
import com.meta.rule.RuleRunContext;
import org.springframework.util.StringUtils;

public class PartySaveWiredRuleImpl implements WiredService {
    @Override
    public void doPreWiredMethod(String transactionType, Nv nv, RuleRunContext context) {
        this.preSaveParty(nv,context);
    }
    @Override
    public void doPostWiredMethod(String transactionType, Nv nv, RuleRunContext context) {
        this.postSaveParty(nv, context);
    }
    private void preSaveParty(Nv nv, RuleRunContext context) {
        String partyCode = nv.getRawStringByName("partyCode");
        CounterService counterService = (CounterService) SpringBeanUtil.getBean("counterServiceImpl");
        if (StringUtils.isEmpty(partyCode)) {
            partyCode = counterService.nextCounterStr(ConstDef.COUNTER_TYPE_PARTY_CODE);
            nv.setStringFvByName("partyCode", partyCode);
        }
    }
    private void postSaveParty(Nv nv, RuleRunContext context) {
    }
}
